package com.woniuxy.project115.kaer.platform.controller;


import com.woniuxy.project115.kaer.commons.util.Result;
import com.woniuxy.project115.kaer.platform.annotation.RequirePermission;
import com.woniuxy.project115.kaer.platform.annotation.RequireRole;
import com.woniuxy.project115.kaer.platform.entity.Role;
import com.woniuxy.project115.kaer.platform.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fyy
 * @since 2025年02月23日
 */
@RestController
@RequestMapping("/role")
@Api(tags = "角色管理")
public class RoleController {
    @Resource
    private RoleService roleService;

    //添加管理员角色接口
    @PostMapping("/addAdminRole")
    @ApiOperation("添加角色接口")
    @RequireRole("超级管理员")
    @RequirePermission("添加角色")
    public Result addAdminRole(String roleName, String remarks) throws Exception {
        roleService.addAdminRole(roleName,remarks);
        return Result.succeed("新增角色成功",null);
    }

    //查询所有角色接口
    @GetMapping("/getAllRole")
    @ApiOperation("查询所有角色接口")
    @RequireRole("超级管理员")
    @RequirePermission("查询所有角色")
    public Result getAllRole() throws Exception {
        final List<Role> roles = roleService.getAllRole();
        return Result.succeed("查询所有角色成功",roles);
    }

    //根据角色名称删除角色接口
    @DeleteMapping("/deleteRoleById/{roleId}")
    @ApiOperation("根据角色Id删除角色接口")
    @RequireRole("超级管理员")
    @RequirePermission("/role/deleteRoleById")
    public Result deleteRoleByName(@PathVariable("roleId") Integer roleId) throws Exception {
        roleService.deleteRoleByName(roleId);
        return Result.succeed("删除角色成功",null);
    }

}

